package actions;

import bin.Mud;
import items.Item;
import mobs.NPC;

public class LookDecider {

    private Mud mudWindow;

    public LookDecider(Mud mudWindow) {
        this.mudWindow = mudWindow;
    }

    public boolean isLookRoom() {
        String look = mudWindow.getCommand();
        return (look.equals("LOOK") || look.equals("L") || look.equals("LOOK AROUND"));
    }

    public boolean isLookMob() {
        String s = mudWindow.getCommand().replaceFirst("LOOK ", "");
        boolean rtn = false;
        for (NPC mob : mudWindow.getRoom().getActiveNPCs()) {
            if (mob.getName().equalsIgnoreCase(s) || mob.getShortName().equalsIgnoreCase(s)) {
                rtn = true;
            }
        }
        return rtn;
    }

    public void doLookRoom() {
        mudWindow.setReturnText(mudWindow.getRoomLongDescription());
        mudWindow.setReturnText("\nMore things to look at:");
        if (!mudWindow.getRoom().showMobs().isEmpty()) {
            mudWindow.setReturnText("Mobs:\n" + mudWindow.getRoom().showMobs());
        }
        if (!mudWindow.getRoom().showItems().isEmpty()) {
            mudWindow.setReturnText("Items:\n" + mudWindow.getRoom().showItems());
        }
        if (mudWindow.getRoom().showMobs().isEmpty() && mudWindow.getRoom().showItems().isEmpty()) {
            mudWindow.setReturnText("nothing");
        }
    }

    public boolean isLookContainer() {
        String s = mudWindow.getCommand().replaceFirst("LOOK ", "");
        String s2 =  mudWindow.getCommand().replaceFirst("L ", "");
        boolean rtn = false;
        for (Item item : mudWindow.getRoom().getRoomItems()) {
            if ((item.getTitle().equalsIgnoreCase(s) || item.getShortName().equalsIgnoreCase(s)) 
                    || (item.getTitle().equalsIgnoreCase(s2) || item.getShortName().equalsIgnoreCase(s2))) {
                rtn = true;
            }
        }
        return rtn;
    }

    public boolean isLook() {
        String look = mudWindow.getCommand();
        return (look.startsWith("LOOK") || look.startsWith("L ") || look.equals("L"));
    }
}